import {
  SHOW_SUCCESS_MSG,
  SHOW_ERROR_MSG,
} from '../mutation-types'

// initial state
const state = {
  count: 0,
  messagecode: '', //消息编码
  message: '', //消息内容
  time: 2000, //显示时间
  type: 'text', //类型，可选值 success, warn, cancel, text
  position: 'bottom', //显示位置，可选值 default, top, middle, bottom
  needRedirect: false, //是否需要路由跳转
  redirectPathName: '', //路由跳转路径的name 如 Main
  needGoBack: false //是否需要路由回退
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
  [SHOW_SUCCESS_MSG](state, msg) {
    state.type = msg.type || "text";
    state.messagecode = msg.messagecode || undefined;
    state.message = msg.message;
    state.time = msg.time || 1000;
    state.position = msg.position || 'bottom';
    state.needRedirect = msg.needRedirect || false;
    state.redirectPathName = msg.redirectPathName || '';
    state.needGoBack = msg.needGoBack || false;
    state.count = state.count + 1;
  },
  [SHOW_ERROR_MSG](state, msg) {
    state.type = msg.type || "warn";
    state.messagecode = msg.messagecode || undefined;
    state.message = msg.message;
    state.time = msg.time || 3000;
    state.position = msg.position || 'middle';
    state.needRedirect = msg.needRedirect || false;
    state.redirectPathName = msg.redirectPathName || '';
    state.needGoBack = msg.needGoBack || false;
    state.count = state.count + 1;
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
